Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

SourceReference.js ➔ describe(ꞌSourceReferenceꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 64
rs 9.3956

6 Functions

Rating   Name   Duplication   Size   Complexity  
A SourceReference.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 12 1
A SourceReference.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 11 1
A SourceReference.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 6 1
A SourceReference.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1
A SourceReference.js ➔ ... ➔ it(ꞌBuildꞌ) 0 9 1
A SourceReference.js ➔ ... ➔ it(ꞌCreate with mixed dataꞌ) 0 12 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('SourceReference', function(){
5
  
6
  it('Create plain', function(){
7
    var newSourceRef = new GedcomX.SourceReference(),
8
        sourceRef = GedcomX.SourceReference();
9
    assert.instanceOf(newSourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor with new.');
10
    assert.instanceOf(sourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor without new.');
11
  });
12
  
13
  it('Create with JSON', function(){
14
    var ref = GedcomX.SourceReference({
15
      id: 'source-ref',
16
      description: 'http://some/uri',
17
      attribution: {
18
        created: 11121211112
19
      }
20
    });
21
    assert.equal(ref.getId(), 'source-ref');
22
    assert.equal(ref.getDescription(), 'http://some/uri');
23
    assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112);
24
  });
25
  
26
  it('Create with mixed data', function(){
27
    var ref = GedcomX.SourceReference({
28
      id: 'source-ref',
29
      description: 'http://some/uri',
30
      attribution: GedcomX.Attribution({
31
        created: 11121211112
32
      })
33
    });
34
    assert.equal(ref.getId(), 'source-ref');
35
    assert.equal(ref.getDescription(), 'http://some/uri');
36
    assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112);
37
  });
38
  
39
  it('Build', function(){
40
    var ref = GedcomX.SourceReference()
41
      .setId('source-ref')
42
      .setDescription('http://some/uri')
43
      .setAttribution({ created: 11121211112 });
44
    assert.equal(ref.getId(), 'source-ref');
45
    assert.equal(ref.getDescription(), 'http://some/uri');
46
    assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112);
47
  });
48
  
49
  it('toJSON', function(){
50
    var refData = {
51
        id: 'source-ref',
52
        description: 'http://some/uri',
53
        attribution: {
54
          created: 11121211112
55
        }
56
      },
57
      ref = GedcomX.SourceReference(refData);
58
    assert.deepEqual(ref.toJSON(), refData);
59
  });
60
  
61
  it('constructor does not copy instances', function(){
62
    var obj1 = GedcomX.SourceReference();
63
    var obj2 = GedcomX.SourceReference(obj1);
64
    assert.strictEqual(obj1, obj2);
65
  });
66
  
67
});